package jmu.tools.file.sync.util ;


import java.io.File ;

/**
 * Provide interface for abstract task
 * 
 * @author vkushnir
 */
public abstract class AbstractAction
{
    protected static final String NEWLINE = "\n" ;
    protected static final String SEPARATOR = ";" ;
    protected static final String SEPARATOR_BIG = " - " ;
    protected static final String STATUS_OK = "DONE" ;
    protected static final String STATUS_SKIP = "SKIP" ;
    protected static final String STATUS_FAIL = "FAIL" ;

    private LogManager log = null ;
    private SyncResult result = null ;

    /**
     * Create new action
     * 
     * @param log
     * @param result
     */
    public AbstractAction ( final LogManager log, final SyncResult result )
    {
        setLog ( log ) ;
        setResult ( result ) ;
    }

    /**
     * Handle action
     * 
     * @param manager
     * @param source
     * @param destination
     */
    public abstract void handle ( final ThreadManager manager, File source, File destination ) ;

    protected void error ( String message )
    {
        LogManager.error ( message ) ;
    }

    protected LogManager getLog ()
    {
        return log ;
    }

    protected SyncResult getResult ()
    {
        return result ;
    }

    /**
     * Get time difference
     * 
     * @param start
     * @return
     */
    protected long getTime ( final long start )
    {
        return (System.currentTimeMillis () - start) ;
    }

    protected void setLog ( LogManager log )
    {
        if ( null == log )
        {
            throw new IllegalArgumentException ( "logger can't be null" ) ;
        }

        this.log = log ;
    }

    protected void setResult ( final SyncResult result )
    {
        if ( null == result )
        {
            throw new IllegalArgumentException ( "result can't be null" ) ;
        }

        this.result = result ;
    }
}
